<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>税金贷产品匹配评估</title>
    <c:import url="header_evaluating.jsp"/>
</head>
<body>
<header class="customer-header">
   <%-- <h3><a href=""><i class="iconfont icon-xiangzuo-copy"></i></a></span> 税金贷产品匹配评估</h3>--%>
</header>
<form action="" id="topic">
    <p class="base-topic-explain">请按以下选项，依次录入客户的相关信息，系统将会自动评估满足客户实际情况的产品。</p>
    <p class="base-topic-explain explain-1">若无匹配的产品，答题将会中断。</p>
    <div class="base-topic topic-footer">
        <div class="topic-item">
            <h4>${subjectName}<span  class="base-page1"><strong id="topic-count">${sort}</strong>/<em id="all-count">${count}</em></span></h4>
            <ul class="topic-item-list list-this" id="optionsId">
                <c:forEach items="${optionsList}" var="options">
                    <li>
                        <label>
                            <input type="radio" name="options" value="${options.optionsId}"><i></i>
                            <span>${options.optionsName}</span>
                        </label>
                    </li>
                </c:forEach>
            </ul>
        </div>
    </div>
</form>
<button type="button" class="submit-topic btn-class" id="next">
    <c:if test="${sort!=count}">下一题</c:if>
    <c:if test="${sort==count}">提交</c:if>

</button>
<c:import url="footer_evaluating.jsp"/>
<script>
    $(function () {
        setFontSize(375);
        window.alert = function (name) {
            const iframe = document.createElement('IFRAME');
            iframe.style.display = 'none';
            // iframe.setAttribute('src', 'data:text/plain,');
            document.documentElement.appendChild(iframe);
            window.frames[0].window.alert(name);
            iframe.parentNode.removeChild(iframe);
        }
        $('.topic-item-list li').each(function(){
            var isActive=$(this).find('input').prop("checked");
            if(isActive){
                $(this).addClass('active')
            }
        })
        $('.topic-item-list input').change(function () {
            var isChange=$(this).prop("checked");
            var isRaido=$(this).attr("type");
            if(isRaido=="radio") {
                // $(this).parents('ul').find('li').removeClass('active');
                // $(this).parents('li').addClass('active');
                var allItem = $(this).parents('ul').find('li input'),
                    that = this,
                    index = null;
                allItem.each(function(i){
                    if(this == that){
                        index = i;

                    }
                })
                $(this).parents('ul').find('li').removeClass('active');
                $(this).parents('li').addClass('active');
                console.log(index)

                return;
            }
            // if(isChange) {
            //     $(this).parents('li').addClass('active');
            // }else {
            //     $(this).parents('li').removeClass('active');
            // }
        });
        $(document).on("touchstart","#next,#submit-btn",function(){

            var isChecked = false;
            $("#optionsId").find("li").each(function () {
                if($(this).attr("class")=='active'){
                    isChecked = true;
                    return false;
                }
            });
            if(!isChecked){
                alert('请选择一个选项！');
                return;
            }

            var count = '${count}';
            var sort = '${sort}';
            var keyId = '${keyId}';
            var optionsId = $("[name='options']:checked").val();
            //根据选项判断渠道
            $("#next").removeClass("btn-class");
            $.ajax({
                url: sysInfo.basePath + '/api/evaluating/submit_options_channel.do',
                type:'post',
                data:{optionsId:optionsId,keyId:keyId,sort:sort},
                dataType:'json',
                success:function(data){
                    $("#next").addClass("btn-class");
                    if(data.code == 0){
                        var data = data.data;
                        console.log(data);
                        if(typeof data == "undefined" || data == null || data == ""||data.length==0){
                            window.location.href = sysInfo.basePath+"/api/evaluating/customer_taxes_no_channel.html";
                        }else{
                            if(sort < count){
                                var subjectSort = parseInt(sort)+1;
                                window.location.href = sysInfo.basePath+"/api/evaluating/query_paper.html?codeType=LOAN_MATCHING&keyId="+keyId+"&subjectSort="+subjectSort;
                             }else if(sort == count){
                                window.location.href = sysInfo.basePath+"/api/evaluating/customer_taxes_yes_channel.html?keyId="+keyId;
                             }
                        }
                    }else{
                        alert("评测失败")
                    }
                }
            });
        });
    })

</script>
</body>
</html>